package com.kalvin.kvf.modules.dy.service;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kalvin.kvf.common.utils.ShiroKit;
import com.kalvin.kvf.modules.sys.entity.User;
import org.springframework.stereotype.Service;
import com.kalvin.kvf.modules.dy.entity.IntentionCust;
import com.kalvin.kvf.modules.dy.mapper.IntentionCustMapper;

import java.util.List;

/**
 * <p>
 * 抖音客户表 服务实现类
 * </p>
 * @since 2023-10-29 15:32:00
 */
@Service
public class IntentionCustServiceImpl extends ServiceImpl<IntentionCustMapper, IntentionCust> implements IntentionCustService {

    @Override
    public Page<IntentionCust> listIntentionCustPage(IntentionCust intentionCust) {
        User user = ShiroKit.getUser();
        if(!user.getUsername().equals("admin")){
            intentionCust.setPhone(user.getPhone());
        }
        Page<IntentionCust> page = new Page<>(intentionCust.getCurrent(), intentionCust.getSize());
        List<IntentionCust> intentionCusts = baseMapper.selectIntentionCustList(intentionCust, page);
        return page.setRecords(intentionCusts);
    }

    @Override
    public void editnoStatus(List<Long> ids){
        for (Long id: ids) {
            IntentionCust intentionCust = baseMapper.selectById(id);
            intentionCust.setStatus(0);//设置为未联系
            baseMapper.update(intentionCust,new UpdateWrapper<IntentionCust>().lambda().eq(IntentionCust::getId,id));
        }
    }

    @Override
    public void editStatus(List<Long> ids){
        for (Long id: ids) {
            IntentionCust intentionCust = baseMapper.selectById(id);
            intentionCust.setStatus(1);//设置为已联系
            baseMapper.update(intentionCust,new UpdateWrapper<IntentionCust>().lambda().eq(IntentionCust::getId,id));
        }
    }

}
